// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Cannon Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 60 : TYPE_CANNON

// Function declarations
reserve function Cannon_DebugDraw
reserve function Cannon_DebugSpawn

// Static Values

// Tables

function Cannon_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


function Cannon_DebugSpawn
	CreateTempObject(TypeName[Cannon], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].drawOrder = 4
end function

event ObjectMain

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(object[0].state, PlayerObject_HandleMonikaTeleport)
		temp5 = checkResult
		CheckLower(object[0].value1, 20)
		temp5 &= checkResult	
		if temp5 == 0		
			BoxCollisionTest(C_BOX, object.entityPos, -8, -16, 6, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		end if
		if object[0].state == PlayerObject_HandleMonikaTeleport
			if object[0].value1 >= 17
				BoxCollisionTest(C_TOUCH, object.entityPos, -8, -16, 6, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object.direction == FLIP_NONE
						object[currentPlayer].ixpos = object[currentPlayer].collisionLeft
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos += 0x160000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel < 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					else
						object[currentPlayer].ixpos = object[currentPlayer].collisionRight
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos -= 0x160000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel > 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					end if
				end if
			end if			
		end if			
	next

end event


event ObjectDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("SLZ/Objects.gif")
	SpriteFrame(-8, -16, 16, 32, 67, 59)
	foreach (TypeName[Cannon], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next
	SetTableValue(TypeName[Cannon], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Cannon_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Cannon_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
